/**   
* @Title: EntityPersistenceLayerServiceImpl.java 
* @Package com.gomeplus.jdbc.service.impl 
* @Description: 实体持久层公共接口实现  
* @author chenmin-ds   
* @date 2017年5月26日 上午11:36:51 
* @company cn.com.gome
* @version V1.0   
*/ 


package com.gomeplus.jdbc.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gomeplus.jdbc.exception.LogicsSqlException;
import com.gomeplus.jdbc.mapper.PersistenceLayerEditMapper;
import com.gomeplus.jdbc.mapper.PersistenceLayerSerMapper;
import com.gomeplus.jdbc.page.Entitys;
import com.gomeplus.jdbc.page.PageQueryEntitys;
import com.gomeplus.jdbc.service.EntityPersistenceLayerService;

/** 
 * @ClassName: EntityPersistenceLayerServiceImpl 
 * @Description: 实体持久层公共接口实现  
 * @author chenmin-ds 
 * @date 2017年5月26日 上午11:36:51  
 */
@Service
public class EntityPersistenceLayerServiceImpl implements EntityPersistenceLayerService {

	private Logger logger = LoggerFactory.getLogger("EntityPersistenceLayerServiceImpl");
	
	@Override
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public PageQueryEntitys queryPageList(PersistenceLayerSerMapper mapper, PageQueryEntitys entity) throws LogicsSqlException {
		try {
			int count = mapper.queryPageListCount(entity);
			if(count > 0){
				entity.resetTotalCount(count);
				List<Entitys> resultEntity = mapper.queryPageList(entity);
				entity.setList(resultEntity);
			}
			return entity;
		} catch (Exception e) {
			logger.error("根据条件查询数据集合异常(queryPageList)：" , e);
			throw new LogicsSqlException("0209","根据条件查询数据集合失败");
		}
		
	}

	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public PageQueryEntitys queryPageVoList(PersistenceLayerSerMapper mapper, PageQueryEntitys entity) throws LogicsSqlException {
		try {
			int count = mapper.queryPageListCount(entity);
			if(count > 0){
				entity.resetTotalCount(count);
				List<Entitys> resultEntity = mapper.queryPageVoList(entity);
				entity.setList(resultEntity);
			}
			entity.setTotalCount(count);
			return entity;
		} catch (Exception e) {
			logger.error("根据条件查询数据集合异常(queryPageVoList)：" , e);
			throw new LogicsSqlException("0210","根据条件查询数据集合失败");
		}
	}

	
}
